package com.bjsxt;

import java.util.Stack;

//匹配符号的对称性
// ...{....[...(...)....]...}...(....)...[...]...

public class TestStack02 {
    String str = "...{....[....(...)....]....}..(....)..[..]...";
    public void  symmetry(){
        //实例化Stack
        Stack<String> stack = new Stack<>();
        //假设修正法
        boolean flag = true;//假设区配
        //拆分字符串并获取
        for (int i= 0;i<str.length();i++){
            char c= str.charAt(i);
            if(c == '{'){
                stack.push("}");
            }
            if(c == '('){
                stack.push(")");
            }
            if(c == '['){
                stack.push("]");
            }
            //判断符号是否对称  修正
            if(c == '}'|| c ==']'||c ==')'){
                if(stack.empty()){  //stack为空的
                    flag = false;
                    break;
                }
                //stack不为空
                String x = stack.pop(); //获取的字符串
                if(x.charAt(0) != c) {  //将取出来的字符串,转为字符
                    flag = false;
                    break;
                }
            }

        }
        if(!stack.empty()){
            flag = false;
        }
        System.out.println(flag);
    }

    public static void main(String[] args) {
        TestStack02 t = new TestStack02();
        t.symmetry();
    }
}
